//
//  ArtistCell_first.m
//  jingdongfang
//
//  Created by LJL on 2017/8/24.
//  Copyright © 2017年 BOE. All rights reserved.
//

#import "ArtistCell_first.h"
#import "ArtistCollectionCell.h"
#import "IntroViewController.h"
@interface ArtistCell_first ()<UICollectionViewDataSource, UICollectionViewDelegate, UICollectionViewDelegateFlowLayout>

@end

@implementation ArtistCell_first

- (void)layoutSubviews
{
    [super layoutSubviews];
    [self addSubview:self.collectionView];
}

- (UICollectionView *)collectionView
{
    if (!_collectionView)
    {
        UICollectionViewFlowLayout *flow = [[UICollectionViewFlowLayout alloc] init];
        [flow setScrollDirection:UICollectionViewScrollDirectionHorizontal];
        self.collectionView = [[UICollectionView alloc] initWithFrame:CGRectMake(0, 0, KSCREENWIDTH,100) collectionViewLayout:flow];
        self.collectionView.backgroundColor = [UIColor c3Color];
        self.collectionView.delegate = self;
        self.collectionView.dataSource = self;
        self.collectionView.showsVerticalScrollIndicator = YES;//垂直方向
        self.collectionView.showsHorizontalScrollIndicator = NO;//水平方向
        [self.collectionView registerNib:[UINib nibWithNibName:@"ArtistCollectionCell" bundle:nil] forCellWithReuseIdentifier:@"ArtistCollectionCell"];
    }
    return _collectionView;
}

- (void)setDataArr:(NSMutableArray *)dataArr
{
    if (_dataArr != dataArr)
    {
        _dataArr = dataArr;
        [self.collectionView reloadData];
    }
}
- (NSInteger)numberOfSectionsInCollectionView:(UICollectionView *)collectionView
{
    return 1;
}

- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section
{
    return self.dataArr.count > 0 ? self.dataArr.count : 0;
}

//设置item大小
- (CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout sizeForItemAtIndexPath:(NSIndexPath *)indexPath
{
    return CGSizeMake(65, 100);
}

- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath
{
    ArtistCollectionCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"ArtistCollectionCell" forIndexPath:indexPath];
    NSDictionary *dic = self.dataArr[indexPath.row];
    [cell.imageV sd_setImageWithURL:[NSURL URLWithString:dic[@"image"]] placeholderImage:[UIImage imageNamed:@"place_head_Icon"]];
    cell.titleL.text = dic[@"nike"];
    return cell;
}

//设置分区边界
- (UIEdgeInsets)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout insetForSectionAtIndex:(NSInteger)section
{
    return UIEdgeInsetsMake(0, 15, 0, 15);
}
#pragma mark --- item 点击事件
- (void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath
{
    IntroViewController *introVC = [[IntroViewController alloc] init];
    NSDictionary *dic = self.dataArr[indexPath.row];
    introVC.u_id = dic[@"uid"];
    [UIViewController ig_pushViewController:introVC animated:YES];
}
@end
